package com.life.mapper;

import com.github.pagehelper.Page;
import com.life.annotation.AutoFill;
import com.life.enumeration.OperationType;
import com.life.pojo.dto.ArticleDTO;
import com.life.pojo.dto.ArticleQueryDTO;
import com.life.pojo.entity.Article;
import com.life.pojo.vo.ArticleVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ArticleMapper {

    Article selectById(Long id);

    Page<ArticleVO> pageQueryByAdmin(ArticleQueryDTO articleQueryDTO);

    Page<ArticleVO> pageQueryByUser(ArticleQueryDTO articleQueryDTO);

    @Insert("insert into article(title, content, tag_id, picture_id, is_top, status, create_time, update_time)" +
            "values" + " (#{title}, #{content}, #{tagId}, #{pictureId}, #{isTop}, #{status}, #{createTime}, #{updateTime})")
    @AutoFill(OperationType.INSERT)
    void insertArticle(Article article);

    @AutoFill(OperationType.UPDATE)
    void updateArticle(Article article);

    @Delete("update article set is_deleted = 1 where id = #{id}")
    void deleteArticle(Long id);
}
